package com.huangjue.backend.utils;

import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;

public class HttpHeaderUtil {
    /**
     * 创建带有Bearer认证的JSON请求头
     * @param apiKey API密钥（必须非空）
     * @return 配置完成的HttpHeaders对象
     * @throws IllegalArgumentException 当apiKey为空时抛出
     */
    public static HttpHeaders createJsonBearerHeaders(String apiKey) {
        // 参数校验
        if (!StringUtils.hasText(apiKey)) {
            throw new IllegalArgumentException("API key must not be null or empty");
        }

        // 创建并配置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.setBearerAuth(apiKey.trim());

        return headers;
    }
}